package com.acme.team03.net;

import java.io.IOException;

import com.acme.team03.commands.Command;
import com.acme.team03.messages.Message;
import com.acme.team03.net.server.ConnectionDispatcher;

public class SendMessageCommand implements Command {
	private ConnectionDispatcher connDispather;
	private Message msg;

	public SendMessageCommand(Message msg, ConnectionDispatcher connDispatcher) {
		this.connDispather = connDispatcher;
		this.msg = msg;
	}

	@Override
	public void execute() {
		for (Connection connection : connDispather.getAllConnections()) {
			try {
				connection.sendMessage(msg);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
